<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		
		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a href="findoutupdate2.html" class=" mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="aaaa" class="mui-title">公告展示</h1>
			<a onclick="check()" id="aaa" class="mui-icon mui-icon-plusempty mui-pull-right"></a>
		</header>
		<div class="mui-content" id="notice2" >
			<div class="mui-card">
				<!--<div class="mui-card-content">
					<a href="editnote.html">
					<div class="mui-card-content-inner" >
						<p>标题:你好</p>
			 			<p style="color: #333;">这里显示文章摘要，让读者对文章内容有个粗略的概念...</p>
					</div>
					</a>
				</div>-->
				<!--<div class="mui-card-footer">
					<p>Posted on January 18, 2016</p>时间记录
					<button id='confirmBtn' type="button" class="mui-icon mui-icon-trash mui-btn-outlined"></button>
				</div>-->
			<!--	<div class="mui-card-footer">
					<p>Posted on January 18, 2016</p>时间记录
					<button id='confirmBtn' type="button" class="mui-icon mui-icon-trash mui-btn-outlined"></button>
				</div>-->
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/mui.zoom.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" charset="utf-8">
		 mui.init();
		 var loginName=localStorage.getItem("loginName");
		 
		//初始化
 		
 		mui.plusReady(function() {
 				checkWho();
			});
 		
 		//时间的格式转化
		function mmtime(time) {
			var newDate = new Date(time);
			var year = newDate.getFullYear();
			var month = (newDate.getMonth() + 1) < 10 ? "0" + (newDate.getMonth() + 1) : newDate.getMonth() + 1;
			var day = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate();
			var hours = newDate.getHours() < 10 ? "0" + newDate.getHours() : newDate.getHours();
			var minuts = newDate.getMinutes() < 10 ? "0" + newDate.getMinutes() : newDate.getMinutes();
			var seconds = newDate.getSeconds() < 10 ? "0" + newDate.getSeconds() : newDate.getSeconds();
			time = year + "-" + month + "-" + day + " " + hours + ":" + minuts + ":" + seconds;
			return time;
		}
 		
 		
			//公告数据展示
			function notice1(){
				console.log("发送++++++++++++++++==");
				var network=true;
				if(mui.os.plus) {
							mui.plusReady(function() {
								if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
									network = false;
								}
							});
						}
				
				if(network) {
					console.log('网络正常,正在发送请求...');
			 				var whoIs=localStorage.getItem("whoIs");
			 				//console.log("dasdasdasdasdasds"+tt);
							mui.ajax({
								type: "post",
								url: "http://113.71.26.27:8080/tpl/share1/index2",
								async: true,
								data: {},
								timeout: 2000,
								crossDomain: true,
								dataType: "json",
							    
								success: function(data) {
									var noticeData='';
									var noticeData1='';
									console.log('响应成功！');
									console.log("公告数据:"+data);
									var infoList=data;
									 
									
								for(var i=0;i<infoList.length;i++){
									 console.log("infoList[i].content："+infoList[i].content);
									noticeData+="<div class='mui-card'>"
									noticeData+="<div class='mui-card-content'>"
									noticeData+="<div class='mui-card-content-inner'>"
									noticeData+="<p>标题:"+infoList[i].title+"</p>"
									noticeData+="<p style='color: #333;'>内容:"+infoList[i].content+"</p>"
									noticeData+="</div>"
									noticeData+="</div>"
									noticeData+="<div class='mui-card-footer'>"
									noticeData+="<p>发布时间:"+mmtime(infoList[i].createDate)+"<br/>发布者:"+infoList[i].employee.name+"</p>"
									if(whoIs=="true"){
										noticeData+="<button onclick=mevent(" + infoList[i].id + ") class='mui-icon mui-icon-trash mui-btn-blue' ></button>"
									}
									noticeData+="</div>"
									noticeData+="</div>"
								 
								}
								$('#notice2').append(noticeData);

							},
								error: function(xhr, type, errorThrown) {
								 
								}
							});

				} else {
					mui.toast("当前网络不给力，请稍后再试...");
				}
		}
			
				
		
		
		//验证是管理人员才能发布公告
		function check() {
			
		 
				var network=true;
				if(mui.os.plus) {
							mui.plusReady(function() {
								if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
									network = false;
								}
							});
						}
				if(network){
				
					mui.ajax({
						url:"http://113.71.26.27:8080/tpl/share1/checkNotice",
						async:true,
						type: 'post',
						data:{
							loginName:loginName
						},
						success:function(data) {
							console.log("响应成功");
							console.log("data:"+data);
						 
							if(data=="true"){
								//console.log("经理");
								//localStorage.setItem("whoIs","true");
								window.open("notice.html");
								mui.toast("有权限");
								
							}else{
								// tt="0";
								// localStorage.setItem("whoIs","false");
								//console.log("员工");
								
								mui.toast("没权限");

							}
						},
						error: function(xhr, type, errorThrown) {
									plus.nativeUI.toast(errorThrown);
								}
					});
				}else{
					mui.toast("当前网络不给力，请稍后再试...");
				}
				
		}
		
		
			//交互:公告数据删除
			function mevent(id) {
				console.log("id:"+id);
		 		var network=true;
		 		if(mui.os.plus) {
							mui.plusReady(function() {
								if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
									network = false;
								}
							});
						}
		 		if(network){
		 			console.log('网络正常,正在发送请求...');
				var btnArray = ['否', '是'];
			
			mui.confirm('是否删除所选公告吗？', '', btnArray, function(e) {
					if(e.index == 1) {
						mui.toast("删除成功");
						mdelete(id);
						
					} else {
						mui.toast("删除失败");
					}
				});
				
			}else{
				mui.toast("当前网络不给力，请稍后再试...");
			}
		 }
			//ajax删除
			function mdelete(id) {
				var network=true;
				if(mui.os.plus) {
							mui.plusReady(function() {
								if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
									network = false;
								}
							});
						}
				if(network){
				
					mui.ajax({
						url: 'http://113.71.26.27:8080/tpl/share1/deleteNotice?id=' + id,
						async: true,
						type: 'get',
						success: function() {
							window.location.href = "noticeList.html"; //打开noticeList.html页面，并刷新这个页面
						}
					});
				}else{
					mui.toast("当前网络不给力，请稍后再试...");
				}
		}
			
			
			//验证是否是员工
		function checkWho() {
			
			
				var network=true;
				if(mui.os.plus) {
							mui.plusReady(function() {
								if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
									network = false;
								}
							});
						}
				if(network){
				
					mui.ajax({
						url:"http://113.71.26.27:8080/tpl/share1/checkWho",
						async:true,
						type: 'post',
						data:{
							loginName:loginName
						},
						success:function(data) {
							
						 //加入企业
							if(data=="true"){
								
								notice1();
							
							
							}else{
								var noticeData="<center class='center'>你还没加入企业</center>";
								$('#notice2').append(noticeData);
								
								
						 
							}
						},
						error: function(xhr, type, errorThrown) {
									plus.nativeUI.toast(errorThrown);
								}
					});
				}else{
					mui.toast("当前网络不给力，请稍后再试...");
				}

		}
			
				/**
		 * 重写返回事件
		 */
		mui.back = function(){
			
			window.location.href = "findoutupdate2.html";
		}
		</script>
	</body>

</html>